package cn.cqs.redisitem.quartz;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @discription :定时任务的配置
 * @author: cqs
 * @date: 2020-09-26 18:06
 */
//@Configuration
public class QuartzConfig {
    private static final String LIKE_TASK_IDENTITY = "LikeTaskQuartz";

    /**
     * 功能描述 :创建任务job
     *
     * @return org.quartz.JobDetail
     * @author cqs
     * @date 2020/9/26
     */

    @Bean
    public JobDetail quartzDetail() {
        return JobBuilder.newJob(RedisDataBaseSynchrQuartz.class)//ReidsQuartz是自定义的定时器
                .withIdentity(LIKE_TASK_IDENTITY)
                .storeDurably()
                .build();
    }

    /**
     * 功能描述 :创建触发器trigger
     *
     * @return org.springframework.scheduling.Trigger
     * @author cqs
     * @date 2020/9/26
     */

    @Bean
    public Trigger quartzTrigger() {
//        使用简单实现类创建计划SimpleScheduleBuilder.simpleSchedule()
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//                .withIntervalInSeconds(10)  //设置时间周期单位秒
                .withIntervalInHours(1)  //一个小时执行一次
                .repeatForever();
        return TriggerBuilder.newTrigger()
                .forJob(quartzDetail())
                .withIdentity(LIKE_TASK_IDENTITY)
                .withSchedule(scheduleBuilder)
                .build();
    }

}
